package com.zeji.androidadvance.utils;

import android.app.Activity;
import android.content.ComponentName;
import android.content.Intent;
import com.blankj.utilcode.util.ActivityUtils;

public class ActivityJumpUtil {
    private Intent intent;

    private ActivityJumpUtil(Intent intent) {
        this.intent = intent;
    }

    public static ActivityJumpUtil obtainBuilder(Class<?> target) {
        Activity nowTop = ActivityUtils.getTopActivity();
        return new ActivityJumpUtil(new Intent(nowTop, target));
    }

    public static ActivityJumpUtil obtainBuilder(String intent) {
        return new ActivityJumpUtil(new Intent(intent));
    }

    public ActivityJumpUtil putExtra(String name, String value) {
        intent.putExtra(name, value);
        return this;
    }

    public void jump() {
        if (intent == null) {
            return;
        }
        try {
            ActivityUtils.getTopActivity().startActivity(intent);
        } catch (Exception ignore) {
            CommonUtil.log("intent 跳转失败");
        }
        intent = null;
    }
}
